from OWRpy import * 
import redRi18n
_ = redRi18n.get_(package = 'compositions')

import signals
import redRGUI

class forest_meta(OWRpy): 
    globalSettingsList = ['commit']
    settingsList = []
    def __init__(self, **kwargs):
        OWRpy.__init__(self, **kwargs)

        self.setRvariableNames(["forest.meta"])
        self.data = {}

        # Python variables
        self.data = {}
        self.RFunctionParam_object = ''
        
        #Inputs
        self.inputs.addInput("X", "X", signals.metaanalysis.MetaMeta, self.processobject) # create a new signal
        
        # GUI
        ## tabs
        self.RFunctionParam_GUI_tabs = redRGUI.base.tabWidget(self.controlArea)
        self.RFunctionParam_GUI_tabsgeneral = self.RFunctionParam_GUI_tabs.createTabPage(name = "General",orientation='vertical')
        self.RFunctionParam_GUI_tabslabels = self.RFunctionParam_GUI_tabs.createTabPage(name = "Labels",orientation='vertical')
        self.RFunctionParam_GUI_tabslines = self.RFunctionParam_GUI_tabs.createTabPage(name = "Lines",orientation='vertical')
        self.RFunctionParam_GUI_tabsdisplay = self.RFunctionParam_GUI_tabs.createTabPage(name = "Display",orientation='vertical')
        self.RFunctionParam_GUI_tabscolors = self.RFunctionParam_GUI_tabs.createTabPage(name = "Colors",orientation='vertical')
        self.RFunctionParam_GUI_tabsfontsize = self.RFunctionParam_GUI_tabs.createTabPage(name = "Font size",orientation='vertical')
        self.RFunctionParam_GUI_tabsfontface = self.RFunctionParam_GUI_tabs.createTabPage(name = "Font face",orientation='vertical')
        self.RFunctionParam_GUI_tabsgaps = self.RFunctionParam_GUI_tabs.createTabPage(name = "Gaps",orientation='vertical')
        self.RFunctionParam_GUI_tabsadvanced = self.RFunctionParam_GUI_tabs.createTabPage(name = "Advanced",orientation='vertical')
        self.RFunctionParam_GUI_tabsPlot = self.RFunctionParam_GUI_tabs.createTabPage(name = "Plot", orientation = 'vertical')
        
        ## General
        self.RFunctionParam_xlim = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgeneral, label = 'The x limits (min,max) of the plot, or the character "s" to produce symmetric forest plots (xlim):', text = '') # general
        self.RFunctionParam_ref = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgeneral, label = "Numerical giving the reference value to be plotted as a line in the forest plot (ref):", text = '0') #lines # general
        
        self.RFunctionParam_GUI_tabsgeneral_col = redRGUI.base.groupBox(self.RFunctionParam_GUI_tabsgeneral, orientation="horizontal")
        
        ### left metabin
        self.RFunctionParam_generalOptions_metabin = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Binary data left column", 
        buttons = [('studlab','Study labels'),
        ('event.e','Number of events in experimental group'),
        ('n.e','Number of observations in experimental group'),
        ('event.c','Number of events in control group'),
        ('n.c','Number of observations in control group')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metabin.hide()
        
        ### left metacont
        self.RFunctionParam_generalOptions_metacont = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Continuous data left column", 
        buttons = [('studlab','Study labels'),
        ('n.e','Number of observations in experimental group'),
        ('mean.e','Estimated mean in experimental group'),
        ('sd.e','Standard deviation in experimental group'),
        ('n.c','Number of observations in control group'),
        ('mean.c','Estimated mean in control group'),
        ('sd.c','Standard deviation in control group')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metacont.hide()
        
        ### left metagen
        self.RFunctionParam_generalOptions_metagen = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Generic inverse variance left column", 
        buttons = [('studlab','Study labels'),
        ('TE','Estimate of treatment effect'),
        ('seTE','Standard error of treatment estimate')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metagen.hide()
        
        ### left metaprop
        self.RFunctionParam_generalOptions_metaprop = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Single proportions left column", 
        buttons = [('studlab','Study labels'),
        ('event','Number of events'),
        ('n','Number of observations')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metaprop.hide()
        
        ### left metacor
        self.RFunctionParam_generalOptions_metacor = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Correlations left column", 
        buttons = [('studlab','Study labels'),
        ('n','Number of observations')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metacor.hide()
        
        ### left metacum
        self.RFunctionParam_generalOptions_metacum = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Cumulative left column", 
        buttons = [('studlab','Study labels')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metacum.hide()
        
        ### left metainf
        self.RFunctionParam_generalOptions_metainf = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Influence analysis left column", 
        buttons = [('studlab','Study labels')],
        setChecked=['studlab'],orientation='vertical')
        self.RFunctionParam_generalOptions_metainf.hide()
        
        ### right
        self.RFunctionParam_generalOptions_rightcol = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral_col,  label = "Right column", 
        buttons = [('effect','Effect sizes'),
        ('ci','Confidence intervals'),
        ('w.fixed','Weights of fixed effect'),
        ('w.random','Weights of random effect')],
        setChecked=['effect','ci'],orientation='vertical')
        
        
        self.RFunctionParam_at = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgeneral, label = "Tick marks at (at):", text = 'NULL') # general
        self.RFunctionParam_generalOptions = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsgeneral,  label = "General options", 
        buttons = [('allstudies','Should studies with inestimable treatment effects be plotted (allstudies)?'),
        ('overall','Should overall summaries be plotted (overall)?')],
        setChecked=['allstudies','overall'],orientation='vertical')
        
        
        ## Labels
        self.RFunctionParam_text_fixed = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "Label of the pooled fixed effect estimate (text.fixed):", text = '"Fixed effect model"')
        self.RFunctionParam_text_random = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "Label of the pooled random effect estimate (text.random):", text = '"Random effect model"')
        self.RFunctionParam_text_fixed_w = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "Label of the pooled fixed effect estimate within subgroups (text.fixed.w):", text = '')
        self.RFunctionParam_text_random_w = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "Label of the pooled random effect estimate within subgroups (text.random.w):", text = '')
        self.RFunctionParam_xlab = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "Label for x axis (xlab):", text = 'NULL') # labels
        self.RFunctionParam_xlab_pos = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "A numeric specifying the center of the label on the x axis (xlab.pos):", text = '') # labels
        self.RFunctionParam_leftlabs = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "leftlabs:", text = '')
        self.RFunctionParam_rightlabs = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabslabels, label = "rightlabs:", text = '')
        self.RFunctionParam_labelsOptions = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabslabels,  label = "Labels options", 
        buttons = [('label','Draw the labels on the tick marks (label)?')],
        setChecked=['label'],orientation='vertical')

        
        ## Lines
        self.RFunctionParam_GUI_tabslines_1 = redRGUI.base.groupBox(self.RFunctionParam_GUI_tabslines, orientation='horizontal')
        self.RFunctionParam_lty_fixed = redRGUI.base.listBox(self.RFunctionParam_GUI_tabslines_1, label = 'Line type (pooled fixed effect estimate; lty.fixed):',
        selectionMode = QAbstractItemView.ExtendedSelection,
        items = [(1,'________'), (2,'- - - -'), (3,'........'), (4,'_._._._.'), (5,'__ __ __'), (6,'__.__.__.')])
        self.RFunctionParam_lty_fixed.setSelectedIds([2])
        self.RFunctionParam_lty_random = redRGUI.base.listBox(self.RFunctionParam_GUI_tabslines_1, label = 'Line type (pooled random effect estimate; lty.random):',
        selectionMode = QAbstractItemView.ExtendedSelection,
        items = [(1,'________'), (2,'- - - -'), (3,'........'), (4,'_._._._.'), (5,'__ __ __'), (6,'__.__.__.')])
        self.RFunctionParam_lty_random.setSelectedIds([3])
        self.RFunctionParam_lwd = redRGUI.base.spinBox(self.RFunctionParam_GUI_tabslines, label='Line width (lwd):', min = 1,max=5, value = 1 )
        
        ## Display
        self.RFunctionParam_hetlab = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsdisplay, label = "Label printed in front of results for heterogeneity measures (hetlab):", text = '"Heterogeneity:"')
        self.RFunctionParam_displayOptions = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsdisplay,  label = "Display options", 
        buttons = [('pooled.totals','Should the total number of observations  be given in the figure (pooled.totals)?'),
        ('pooled.events','Should the total number of events be given in the figure (pooled.events)?'),
        ('print.I2','Print the value of the I-squared statistic (print.I2)?'), 
        ('print.tau2','Print the value of the between-study variance tau-squared (print.tau2)?'), 
        ('print.Q','Print the value of the heterogeneity statistic Q (print.Q)?'),
        ('print.pval.Q','Print the value of the p-value of the heterogeneity statistic Q (print.pval.Q)?') 
        ],
        setChecked=['pooled.totals','print.I2','print.tau2','print.pval.Q'],orientation='vertical')
        

        
        ## Colors
        self.RFunctionParam_col_i = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_i:", text = 'black')
        self.RFunctionParam_col_i_inside_square = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_i_inside_square:", text = 'white')
        self.RFunctionParam_col_square = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_square:", text = 'gray')
        self.RFunctionParam_col_square_lines = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_square_lines:", text = '')
        self.RFunctionParam_col_diamond = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_diamond:", text = 'gray')
        self.RFunctionParam_col_diamond_fixed = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_diamond_fixed:", text = '')
        self.RFunctionParam_col_diamond_random = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_diamond_random:", text = '')
        self.RFunctionParam_col_diamond_lines = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_diamond_lines:", text = 'black')
        self.RFunctionParam_col_diamond_fixed_lines = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_diamond_fixed_lines:", text = '')
        self.RFunctionParam_col_diamond_random_lines = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_diamond_random_lines:", text = '')
        self.RFunctionParam_col_by = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabscolors, label = "col_by:", text = 'darkgray')
        # self.optionWidgets['titleColor'] = ColorIcon(self.RFunctionParam_GUI_tabscolors ,label='Title') # dummy color picker does not work 
        
        ## Font
        ## size spin boxes
        self.RFunctionParam_fontsize = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fontsize:", text = '12')
        self.RFunctionParam_fs_heading = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_heading:", text = '')
        self.RFunctionParam_fs_fixed = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_fixed:", text = '')
        self.RFunctionParam_fs_random = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_random:", text = '')
        self.RFunctionParam_fs_study = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_study:", text = '')
        self.RFunctionParam_fs_fixed_labels = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_fixed_labels:", text = '')
        self.RFunctionParam_fs_random_labels = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_random_labels:", text = '')
        self.RFunctionParam_fs_study_labels = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_study_labels:", text = '')
        self.RFunctionParam_fs_hetstat = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_hetstat:", text = '')
        self.RFunctionParam_fs_axis = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_axis:", text = '')
        self.RFunctionParam_fs_xlab = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsfontsize, label = "fs_xlab:", text = '')
        
        ## Fontface radiobuttons mettre une constante de choix
        self.RFunctionParam_ff_options = ['plain','italic','bold','bold.italic']
        self.RFunctionParam_ff_heading = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_heading:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_heading.setCurrentId('bold')
        self.RFunctionParam_ff_fixed = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_fixed:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_fixed.setCurrentId('bold')
        self.RFunctionParam_ff_random = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_random:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_random.setCurrentId('plain')
        self.RFunctionParam_ff_study = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_study:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_study.setCurrentId('plain')
        self.RFunctionParam_ff_fixed_labels = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_fixed_labels:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_fixed_labels.setCurrentId('plain')
        self.RFunctionParam_ff_random_labels = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_random_labels:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_random_labels.setCurrentId('plain')
        self.RFunctionParam_ff_study_labels = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_study_labels:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_study_labels.setCurrentId('plain')
        self.RFunctionParam_ff_hetstat = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_hetstat:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_hetstat.setCurrentId('bold.italic')
        self.RFunctionParam_ff_axis = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_axis:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_axis.setCurrentId('plain')
        self.RFunctionParam_ff_xlab = redRGUI.base.comboBox(self.RFunctionParam_GUI_tabsfontface,  label = "ff_xlab:",items = self.RFunctionParam_ff_options)
        self.RFunctionParam_ff_xlab.setCurrentId('plain')


        ## Gap
        self.RFunctionParam_colgap = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgaps, label = "colgap:", text = 'unit(2, "mm")')
        self.RFunctionParam_colgap_left = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgaps, label = "colgap_left:", text = '')
        self.RFunctionParam_colgap_right = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgaps, label = "colgap_right:", text = '')
        self.RFunctionParam_colgap_forest = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgaps, label = "colgap_forest:", text = '')
        self.RFunctionParam_colgap_forest_left = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgaps, label = "colgap_forest_left:", text = '')
        self.RFunctionParam_colgap_forest_right = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsgaps, label = "colgap_forest_right:", text = '')
        
        ## Advanced
        self.RFunctionParam_sortvar = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsadvanced, label = "An optional vector used to sort the individual studies (sortvar):", text = '')
        self.RFunctionParam_squaresize = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsadvanced, label = "squaresize:", text = '0.8')
        self.RFunctionParam_boxsize = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsadvanced, label = "boxsize:", text = '')
        self.RFunctionParam_plotwidth = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsadvanced, label = "plotwidth:", text = 'unit(6, "cm")')
        self.RFunctionParam_just = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsadvanced, label = "just:", text = '"center"')
        self.RFunctionParam_digits = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsadvanced, label = "digits:", text = '2')
        self.RFunctionParam_advancedOptions = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsadvanced,  label = "Advanced options", 
        buttons = [('addspace','Should additional space (i.e. a blank row) be printed above and below study results (addspace)?'),('new','Should a new figure be printed in an existing graphics window (new)?')],
        setChecked=['addspace','new'],orientation='vertical')
        
        
        ## Not included
        ##self.RFunctionParam_x = redRGUI.base.lineEdit(self.controlArea, label = "x:", text = '') ### signal INPUT
        ##self.RFunctionParam_byvar = redRGUI.base.lineEdit(self.controlArea, label = "byvar:", text = 'x$byvar')
        ##self.RFunctionParam_bylab = redRGUI.base.lineEdit(self.controlArea, label = "bylab:", text = 'x$bylab')
        ##self.RFunctionParam_print_byvar = redRGUI.base.lineEdit(self.controlArea, label = "print_byvar:", text = 'x$print.byvar')
        ##self.RFunctionParam_studlab = redRGUI.base.lineEdit(self.controlArea, label = "studlab:", text = 'TRUE')
        ##self.RFunctionParam_level = redRGUI.base.lineEdit(self.controlArea, label = "level:", text = 'x$level')
        ##self.RFunctionParam_level_comb = redRGUI.base.lineEdit(self.controlArea, label = "level_comb:", text = 'x$level.comb')
        ##self.RFunctionParam_comb_fixed = redRGUI.base.lineEdit(self.controlArea, label = "comb_fixed:", text = 'x$comb.fixed')
        ##self.RFunctionParam_comb_random = redRGUI.base.lineEdit(self.controlArea, label = "comb_random:", text = 'x$comb.random')
        ##self.RFunctionParam_weight = redRGUI.base.lineEdit(self.controlArea, label = "weight:", text = '') ## from incoming data
        ##self.RFunctionParam_pscale = redRGUI.base.lineEdit(self.controlArea, label = "A numeric giving scaling factor for probabilities for objects of class metaprop (pscale):", text = '1') # for metaprop only keep here but keep commented
        #self.RFunctionParam_lab_e = redRGUI.base.lineEdit(self.controlArea, label = "lab_e:", text = 'x$label.e')
        #self.RFunctionParam_lab_c = redRGUI.base.lineEdit(self.controlArea, label = "lab_c:", text = 'x$label.c')
        #self.RFunctionParam_lab_e_attach_to_col = redRGUI.base.lineEdit(self.controlArea, label = "lab_e_attach_to_col:", text = 'NULL')
        #self.RFunctionParam_lab_c_attach_to_col = redRGUI.base.lineEdit(self.controlArea, label = "lab_c_attach_to_col:", text = 'NULL')
        #self.RFunctionParam_hetstat = redRGUI.base.lineEdit(self.RFunctionParam_GUI_tabsdisplay, label = "hetstat:", text = 'print.I2|print.tau2|print.Q|print.pval.Q')
        
        # Commit
        self.commit = redRGUI.base.commitButton(self.bottomAreaRight, _("Commit"), alignment=Qt.AlignLeft, 
        callback = self.commitFunction, processOnInput=True)
        
        self.RFunctionParam_plotExtWin = redRGUI.base.checkBox(self.RFunctionParam_GUI_tabsPlot,  label = "Options", 
        buttons = [('win','Plot in external window.')], orientation='horizontal')
        self.plotArea = redRGUI.plotting.redRPlot(self.RFunctionParam_GUI_tabsPlot, label = "Plot", displayLabel = False)
        self.plotArea.resizeCheck.uncheckAll()
        self.plotArea.topArea.hide()
        
        
    def processobject(self, data):
        if not self.require_librarys(["meta"]):
            self.status.setText('R Libraries Not Loaded.')
            return
        if data:
            self.RFunctionParam_object=data.getData()
            self.data = data
            self.RFunctionParam_objectclass=self.R('class('+unicode(self.RFunctionParam_object)+')')
            
            if 'metabin' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.show()
                self.RFunctionParam_generalOptions_metacont.hide()
                self.RFunctionParam_generalOptions_metagen.hide()
                self.RFunctionParam_generalOptions_metaprop.hide()
                self.RFunctionParam_generalOptions_metacor.hide()
                self.RFunctionParam_generalOptions_metacum.hide()
                self.RFunctionParam_generalOptions_metainf.hide()
            if 'metacont' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.hide()
                self.RFunctionParam_generalOptions_metacont.show()
                self.RFunctionParam_generalOptions_metagen.hide()
                self.RFunctionParam_generalOptions_metaprop.hide()
                self.RFunctionParam_generalOptions_metacor.hide()
                self.RFunctionParam_generalOptions_metacum.hide()
                self.RFunctionParam_generalOptions_metainf.hide()
            if 'metagen' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.hide()
                self.RFunctionParam_generalOptions_metacont.hide()
                self.RFunctionParam_generalOptions_metagen.show()
                self.RFunctionParam_generalOptions_metaprop.hide()
                self.RFunctionParam_generalOptions_metacor.hide()
                self.RFunctionParam_generalOptions_metacum.hide()
                self.RFunctionParam_generalOptions_metainf.hide()
            if 'metaprop' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.hide()
                self.RFunctionParam_generalOptions_metacont.hide()
                self.RFunctionParam_generalOptions_metagen.hide()
                self.RFunctionParam_generalOptions_metaprop.show()
                self.RFunctionParam_generalOptions_metacor.hide()
                self.RFunctionParam_generalOptions_metacum.hide()
                self.RFunctionParam_generalOptions_metainf.hide()         
            if 'metacor' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.hide()
                self.RFunctionParam_generalOptions_metacont.hide()
                self.RFunctionParam_generalOptions_metagen.hide()
                self.RFunctionParam_generalOptions_metaprop.hide()
                self.RFunctionParam_generalOptions_metacor.show()
                self.RFunctionParam_generalOptions_metacum.hide()
                self.RFunctionParam_generalOptions_metainf.hide()
            if 'metacum' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.hide()
                self.RFunctionParam_generalOptions_metacont.hide()
                self.RFunctionParam_generalOptions_metagen.hide()
                self.RFunctionParam_generalOptions_metaprop.hide()
                self.RFunctionParam_generalOptions_metacor.hide()
                self.RFunctionParam_generalOptions_metacum.show()
                self.RFunctionParam_generalOptions_metainf.hide()
            if 'metainf' in self.RFunctionParam_objectclass:
                self.RFunctionParam_generalOptions_metabin.hide()
                self.RFunctionParam_generalOptions_metacont.hide()
                self.RFunctionParam_generalOptions_metagen.hide()
                self.RFunctionParam_generalOptions_metaprop.hide()
                self.RFunctionParam_generalOptions_metacor.hide()
                self.RFunctionParam_generalOptions_metacum.hide()
                self.RFunctionParam_generalOptions_metainf.show()
            
            if self.commit.processOnInput():
                self.commitFunction()
        else:
            self.RFunctionParam_object=''
            
        
    def commitFunction(self):
        injection = []

        # General
        if unicode(self.RFunctionParam_xlim.text()) != '':
            string = 'xlim='+unicode(self.RFunctionParam_xlim.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_ref.text()) != '':
            string = 'ref='+unicode(self.RFunctionParam_ref.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_at.text()) != '':
            string = 'at='+unicode(self.RFunctionParam_at.text())+''
            injection.append(string)
        if 'allstudies' in self.RFunctionParam_generalOptions.getCheckedIds(): 
            string='allstudies=TRUE'
            injection.append(string)
        else:
            string='allstudies=FALSE'
            injection.append(string)
        if 'overall' in self.RFunctionParam_generalOptions.getCheckedIds(): 
            string='overall=TRUE'
            injection.append(string)
        else:
            string='overall=FALSE'
            injection.append(string)
        
        # Left column injections
        injectionleftcol=[]
        if 'metabin' in self.RFunctionParam_objectclass:
            if 'studlab' in self.RFunctionParam_generalOptions_metabin.getCheckedIds(): injectionleftcol.append('"studlab"')
            if 'event.e' in self.RFunctionParam_generalOptions_metabin.getCheckedIds(): injectionleftcol.append('"event.e"')
            if 'n.e' in self.RFunctionParam_generalOptions_metabin.getCheckedIds(): injectionleftcol.append('"n.e"')
            if 'event.c' in self.RFunctionParam_generalOptions_metabin.getCheckedIds(): injectionleftcol.append('"event.c"')
            if 'n.c' in self.RFunctionParam_generalOptions_metabin.getCheckedIds(): injectionleftcol.append('"n.c"')
        elif 'metacont' in self.RFunctionParam_objectclass:
            if 'studlab' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"studlab"')
            if 'n.e' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"n.e"')
            if 'mean.e' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"mean.e"')
            if 'sd.e' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"sd.e"')
            if 'n.c' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"n.c"')
            if 'mean.c' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"mean.c"')
            if 'sd.c' in self.RFunctionParam_generalOptions_metacont.getCheckedIds(): injectionleftcol.append('"sd.c"')
        elif 'metagen' in self.RFunctionParam_objectclass:
            if 'studlab' in self.RFunctionParam_generalOptions_metagen.getCheckedIds(): injectionleftcol.append('"studlab"')
            if 'TE' in self.RFunctionParam_generalOptions_metagen.getCheckedIds(): injectionleftcol.append('"mean.e"')
            if 'seTE' in self.RFunctionParam_generalOptions_metagen.getCheckedIds(): injectionleftcol.append('"sd.e"')
        elif 'metaprop' in self.RFunctionParam_objectclass:
            if 'studlab' in self.RFunctionParam_generalOptions_metaprop.getCheckedIds(): injectionleftcol.append('"studlab"')
            if 'event' in self.RFunctionParam_generalOptions_metaprop.getCheckedIds(): injectionleftcol.append('"event"')
            if 'n' in self.RFunctionParam_generalOptions_metaprop.getCheckedIds(): injectionleftcol.append('"n"')
        elif 'metacor' in self.RFunctionParam_objectclass:
            if 'studlab' in self.RFunctionParam_generalOptions_metacor.getCheckedIds(): injectionleftcol.append('"studlab"')
            if 'n' in self.RFunctionParam_generalOptions_metacor.getCheckedIds(): injectionleftcol.append('"n"')
        elif 'metacum' in self.RFunctionParam_objectclass:
            if 'studlab' in self.RFunctionParam_generalOptions_metacum.getCheckedIds(): injectionleftcol.append('"studlab"')
        elif 'metainf' in self.RFunctionParam_objectclass:
            injectionleftcol=[]
            if 'studlab' in self.RFunctionParam_generalOptions_metainf.getCheckedIds(): injectionleftcol.append('"studlab"')
        string = ','.join(injectionleftcol)
        injection.append('leftcols=c('+string+')')
        
        
        # Right column injections
        injectionrightcol=[]
        if 'effect' in self.RFunctionParam_generalOptions_rightcol.getCheckedIds(): injectionrightcol.append('"effect"')
        if 'ci' in self.RFunctionParam_generalOptions_rightcol.getCheckedIds(): injectionrightcol.append('"ci"')
        if 'w.fixed' in self.RFunctionParam_generalOptions_rightcol.getCheckedIds(): injectionrightcol.append('"w.fixed"')
        if 'w.random' in self.RFunctionParam_generalOptions_rightcol.getCheckedIds(): injectionrightcol.append('"w.random"')
        string = ','.join(injectionrightcol)
        injection.append('rightcols=c('+string+')')

            
            
        # Labels
        if unicode(self.RFunctionParam_leftlabs.text()) != '':
            string = 'leftlabs='+unicode(self.RFunctionParam_leftlabs.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_rightlabs.text()) != '':
            string = 'rightlabs='+unicode(self.RFunctionParam_rightlabs.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_text_fixed_w.text()) != '':
            string = 'text.fixed.w='+unicode(self.RFunctionParam_text_fixed_w.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_text_random.text()) != '':
            string = 'text.random='+unicode(self.RFunctionParam_text_random.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_xlab_pos.text()) != '':
            string = 'xlab.pos='+unicode(self.RFunctionParam_xlab_pos.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_xlab.text()) != '':
            string = 'xlab='+unicode(self.RFunctionParam_xlab.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_text_fixed.text()) != '':
            string = 'text.fixed='+unicode(self.RFunctionParam_text_fixed.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_text_random_w.text()) != '':
            string = 'text.random.w='+unicode(self.RFunctionParam_text_random_w.text())+''
            injection.append(string)
        if 'label' in self.RFunctionParam_labelsOptions.getCheckedIds(): 
            string='label=TRUE'
            injection.append(string)
        else:
            string='label=FALSE'
            injection.append(string)

        
        # Lines
        if unicode(self.RFunctionParam_lty_random.selectedIds()) != '':
            string = 'lty.random='+unicode(self.RFunctionParam_lty_random.selectedIds()[0])+''
            injection.append(string)
        if unicode(self.RFunctionParam_lty_fixed.selectedIds()) != '':
            string = 'lty.fixed='+unicode(self.RFunctionParam_lty_fixed.selectedIds()[0])+''
            injection.append(string)
        if unicode(self.RFunctionParam_lwd.value()) != '':
            string = 'lwd='+unicode(self.RFunctionParam_lwd.value())+''
            injection.append(string)

        
        
        # Display
        if unicode(self.RFunctionParam_hetlab.text()) != '':
            string = 'hetlab='+unicode(self.RFunctionParam_hetlab.text())+''
            injection.append(string)
        if 'print.pval.Q' in self.RFunctionParam_displayOptions.getCheckedIds(): 
            string='print.pval.Q=TRUE'
            injection.append(string)
        else:
            string='print.pval.Q=FALSE'
            injection.append(string)
        if 'pooled.events' in self.RFunctionParam_displayOptions.getCheckedIds(): 
            string='pooled.events=TRUE'
            injection.append(string)
        else:
            string='pooled.events=FALSE'
            injection.append(string)
        if 'pooled.totals' in self.RFunctionParam_displayOptions.getCheckedIds(): 
            string='pooled.totals=TRUE'
            injection.append(string)
        else:
            string='pooled.totals=FALSE'
            injection.append(string)
        if 'print.Q' in self.RFunctionParam_displayOptions.getCheckedIds(): 
            string='print.Q=TRUE'
            injection.append(string)
        else:
            string='print.Q=FALSE'
            injection.append(string)
        if 'print.tau2' in self.RFunctionParam_displayOptions.getCheckedIds(): 
            string='print.tau2=TRUE'
            injection.append(string)
        else:
            string='print.tau2=FALSE'
            injection.append(string)
        if 'print.I2' in self.RFunctionParam_displayOptions.getCheckedIds(): 
            string='print.I2=TRUE'
            injection.append(string)
        else:
            string='print.I2=FALSE'
            injection.append(string)


        # Colors
        if unicode(self.RFunctionParam_col_diamond.text()) != '':
            string = 'col.diamond="'+unicode(self.RFunctionParam_col_diamond.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_square_lines.text()) != '':
            string = 'col.square.lines="'+unicode(self.RFunctionParam_col_square_lines.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_diamond_fixed.text()) != '':
            string = 'col.diamond.fixed="'+unicode(self.RFunctionParam_col_diamond_fixed.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_diamond_lines.text()) != '':
            string = 'col.diamond.lines="'+unicode(self.RFunctionParam_col_diamond_lines.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_by.text()) != '':
            string = 'col.by="'+unicode(self.RFunctionParam_col_by.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_diamond_random_lines.text()) != '':
            string = 'col.diamond.random.lines="'+unicode(self.RFunctionParam_col_diamond_random_lines.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_diamond_random.text()) != '':
            string = 'col.diamond.random="'+unicode(self.RFunctionParam_col_diamond_random.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_square.text()) != '':
            string = 'col.square="'+unicode(self.RFunctionParam_col_square.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_i.text()) != '':
            string = 'col.i="'+unicode(self.RFunctionParam_col_i.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_i_inside_square.text()) != '':
            string = 'col.i.inside.square="'+unicode(self.RFunctionParam_col_i_inside_square.text())+'"'
            injection.append(string)
        if unicode(self.RFunctionParam_col_diamond_fixed_lines.text()) != '':
            string = 'col.diamond.fixed.lines="'+unicode(self.RFunctionParam_col_diamond_fixed_lines.text())+'"'
            injection.append(string)
            

        # Font size
        if unicode(self.RFunctionParam_fontsize.text()) != '':
            string = 'fontsize='+unicode(self.RFunctionParam_fontsize.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_study.text()) != '':
            string = 'fs.study='+unicode(self.RFunctionParam_fs_study.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_study_labels.text()) != '':
            string = 'fs.study.labels='+unicode(self.RFunctionParam_fs_study_labels.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_xlab.text()) != '':
            string = 'fs.xlab='+unicode(self.RFunctionParam_fs_xlab.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_fixed.text()) != '':
            string = 'fs.fixed='+unicode(self.RFunctionParam_fs_fixed.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_axis.text()) != '':
            string = 'fs.axis='+unicode(self.RFunctionParam_fs_axis.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_fixed_labels.text()) != '':
            string = 'fs.fixed.labels='+unicode(self.RFunctionParam_fs_fixed_labels.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_hetstat.text()) != '':
            string = 'fs.hetstat='+unicode(self.RFunctionParam_fs_hetstat.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_heading.text()) != '':
            string = 'fs.heading='+unicode(self.RFunctionParam_fs_heading.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_fs_random_labels.text()) != '':
            string = 'fs.random.labels='+unicode(self.RFunctionParam_fs_random_labels.text())+''
        if unicode(self.RFunctionParam_fs_random.text()) != '':
            injection.append(string)
            string = 'fs.random="'+unicode(self.RFunctionParam_fs_random.text())+'"'
            injection.append(string)
            
        
        # Font face

        string = 'ff.fixed="'+unicode(self.RFunctionParam_ff_fixed.currentId())+'"'
        injection.append(string)
        string = 'ff.heading="'+unicode(self.RFunctionParam_ff_heading.currentId())+'"'
        injection.append(string)
        string = 'ff.random="'+unicode(self.RFunctionParam_ff_random.currentId())+'"'
        injection.append(string)
        string = 'ff.study="'+unicode(self.RFunctionParam_ff_study.currentId())+'"'
        injection.append(string)
        string = 'ff.study.labels="'+unicode(self.RFunctionParam_ff_study_labels.currentId())+'"'
        injection.append(string)
        string = 'ff.random.labels="'+unicode(self.RFunctionParam_ff_random_labels.currentId())+'"'
        injection.append(string)
        string = 'ff.xlab="'+unicode(self.RFunctionParam_ff_xlab.currentId())+'"'
        injection.append(string)
        string = 'ff.fixed.labels="'+unicode(self.RFunctionParam_ff_fixed_labels.currentId())+'"'
        injection.append(string)
        string = 'ff.hetstat="'+unicode(self.RFunctionParam_ff_hetstat.currentId())+'"'
        injection.append(string)
        string = 'ff.axis="'+unicode(self.RFunctionParam_ff_axis.currentId())+'"'
        injection.append(string)
            
        # Gaps
        if unicode(self.RFunctionParam_colgap_forest_right.text()) != '':
            string = 'colgap.forest.right='+unicode(self.RFunctionParam_colgap_forest_right.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_colgap_forest_left.text()) != '':
            string = 'colgap.forest.left='+unicode(self.RFunctionParam_colgap_forest_left.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_colgap.text()) != '':
            string = 'colgap='+unicode(self.RFunctionParam_colgap.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_colgap_left.text()) != '':
            string = 'colgap.left='+unicode(self.RFunctionParam_colgap_left.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_colgap_right.text()) != '':
            string = 'colgap.right='+unicode(self.RFunctionParam_colgap_right.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_colgap_forest.text()) != '':
            string = 'colgap.forest='+unicode(self.RFunctionParam_colgap_forest.text())+''
            injection.append(string)

            
        
        #Advanced
        if unicode(self.RFunctionParam_sortvar.text()) != '':
            string = 'sortvar='+unicode(self.RFunctionParam_sortvar.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_just.text()) != '':
            string = 'just='+unicode(self.RFunctionParam_just.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_boxsize.text()) != '':
            string = 'boxsize='+unicode(self.RFunctionParam_boxsize.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_squaresize.text()) != '':
            string = 'squaresize='+unicode(self.RFunctionParam_squaresize.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_digits.text()) != '':
            string = 'digits='+unicode(self.RFunctionParam_digits.text())+''
            injection.append(string)
        if unicode(self.RFunctionParam_plotwidth.text()) != '':
            string = 'plotwidth='+unicode(self.RFunctionParam_plotwidth.text())+''
            injection.append(string)
        if 'addspace' in self.RFunctionParam_advancedOptions.getCheckedIds(): 
            string='addspace=TRUE'
            injection.append(string)
        else:
            string='addspace=FALSE'
            injection.append(string)
        if 'new' in self.RFunctionParam_advancedOptions.getCheckedIds(): 
            string='new=TRUE'
            injection.append(string)
        else:
            string='new=FALSE'
            injection.append(string)

        inj = ','.join(injection)
        #self.R(self.Rvariables['forest.meta']+'<-forest.meta(x='+unicode(self.RFunctionParam_object)+','+inj+')')
        self.plotArea.plotMultiple(query = 'x='+unicode(self.RFunctionParam_object)+','+inj, function = 'forest.meta') # plotMultiple instead of plot for compliance with 1.85b
        if 'win' in self.RFunctionParam_plotExtWin.getCheckedIds(): 
            self.R('forest.meta(x='+unicode(self.RFunctionParam_object)+', '+inj+')')
        
        self.RFunctionParam_GUI_tabs.setCurrentIndex(9)